unit Class_Dict;

interface
uses
  Classes,SysUtils,Uni,UniEngine;

type
  TDict=class(TUniEngine)
  private
    FDictIdex: Integer;
    FDictMode: string;
    FDictInfo: string;
    FDictCode: string;
    FDictName: string;
    FDictMemo: string;
  protected
    procedure SetParameters;override;
    function  GetStrInsert:string;override;
    function  GetStrUpdate:string;override;
    function  GetStrDelete:string;override;
  public
    function  GetStrsIndex:string;override;
  public
    function  GetNextIdex:Integer;overload;
    function  GetNextIdex(AUniConnection:TUniConnection):Integer;overload;
  public
    function  CheckExist(AUniConnection:TUniConnection):Boolean;override;
  public
    destructor  Destroy; override;
    constructor Create;  
  published
    property DictIdex: Integer read FDictIdex write FDictIdex;
    property DictMode: string read FDictMode write FDictMode;
    property DictInfo: string read FDictInfo write FDictInfo;
    property DictCode: string read FDictCode write FDictCode;
    property DictName: string read FDictName write FDictName;
    property DictMemo: string read FDictMemo write FDictMemo;    
  public
    class function  ReadDS(AUniQuery:TUniQuery):TUniEngine;override;
    class procedure ReadDS(AUniQuery:TUniQuery;var Result:TUniEngine);override;
    class function  CopyIt(ADict:TDict):TDict;overload;        
    class procedure CopyIt(ADict:TDict;var Result:TDict);overload;       
  end;

implementation
uses
  Class_KzUtils;

{ TDict }
procedure TDict.SetParameters;
begin
  inherited;
  with FUniSQL.Params do
  begin
    case FOptTyp of
      otAddx:
      begin
        ParamByName('DICT_IDEX').Value := DICTIDEX;
        ParamByName('DICT_MODE').Value := DICTMODE;
        ParamByName('DICT_INFO').Value := DICTINFO;
        ParamByName('DICT_CODE').Value := DICTCODE;
        ParamByName('DICT_NAME').Value := DICTNAME;
        ParamByName('DICT_MEMO').Value := DICTMEMO; 
      end;
      otEdit:
      begin
        ParamByName('DICT_IDEX').Value := DICTIDEX;
        ParamByName('DICT_MODE').Value := DICTMODE;
        ParamByName('DICT_INFO').Value := DICTINFO;
        ParamByName('DICT_CODE').Value := DICTCODE;
        ParamByName('DICT_NAME').Value := DICTNAME;
        ParamByName('DICT_MEMO').Value := DICTMEMO; 
      end;  
      otDelt:
      begin
        ParamByName('DICT_IDEX').Value := DICTIDEX;
 
      end;  
    end;
  end;
end;

function TDict.CheckExist(AUniConnection: TUniConnection): Boolean;
begin
  Result:=CheckExist('TBL_DICT',['DICT_IDEX',DICTIDEX],AUniConnection);
end;

function TDict.GetNextIdex: Integer;
begin

end;

function TDict.GetNextIdex(AUniConnection: TUniConnection): Integer;
begin

end;

function TDict.GetStrDelete: string;
begin
  Result:='DELETE FROM TBL_DICT WHERE   DICT_IDEX=:DICT_IDEX';
end;

function TDict.GetStrInsert: string;
begin
  Result:='INSERT INTO TBL_DICT'
         +'    ( DICT_IDEX, DICT_MODE, DICT_INFO, DICT_CODE, DICT_NAME'
         +'    , DICT_MEMO)'
         +'    VALUES'
         +'    (:DICT_IDEX,:DICT_MODE,:DICT_INFO,:DICT_CODE,:DICT_NAME'
         +'    ,:DICT_MEMO)';
end;

function TDict.GetStrsIndex: string;
begin
  Result:=Format('%D',[DICTIDEX]);
end;

function TDict.GetStrUpdate: string;
begin
  Result:='UPDATE  TBL_DICT SET'
         +'    DICT_MODE=:DICT_MODE,'
         +'    DICT_INFO=:DICT_INFO,'
         +'    DICT_CODE=:DICT_CODE,'
         +'    DICT_NAME=:DICT_NAME,'
         +'    DICT_MEMO=:DICT_MEMO'
         +'    WHERE DICT_IDEX=:DICT_IDEX';
end;

constructor TDict.Create;
begin

end;

destructor TDict.Destroy;
begin

  inherited;
end;

class function TDict.ReadDS(AUniQuery: TUniQuery): TUniEngine;
begin
  Result:=TDict.Create;
  with TDict(Result) do
  begin
    DICTIDEX:=AUniQuery.FieldByName('DICT_IDEX').AsInteger;
    DICTMODE:=AUniQuery.FieldByName('DICT_MODE').AsString;
    DICTINFO:=AUniQuery.FieldByName('DICT_INFO').AsString;
    DICTCODE:=AUniQuery.FieldByName('DICT_CODE').AsString;
    DICTNAME:=AUniQuery.FieldByName('DICT_NAME').AsString;
    DICTMEMO:=AUniQuery.FieldByName('DICT_MEMO').AsString;
  end;  
end;

class procedure TDict.ReadDS(AUniQuery: TUniQuery; var Result: TUniEngine);
begin
  if Result=nil then Exit;
  with TDict(Result) do
  begin
    DICTIDEX:=AUniQuery.FieldByName('DICT_IDEX').AsInteger;
    DICTMODE:=AUniQuery.FieldByName('DICT_MODE').AsString;
    DICTINFO:=AUniQuery.FieldByName('DICT_INFO').AsString;
    DICTCODE:=AUniQuery.FieldByName('DICT_CODE').AsString;
    DICTNAME:=AUniQuery.FieldByName('DICT_NAME').AsString;
    DICTMEMO:=AUniQuery.FieldByName('DICT_MEMO').AsString;
  end;  
end;

class function  TDict.CopyIt(ADict: TDict): TDict;
begin
  Result:=TDict.Create;
  TDict.CopyIt(ADict,Result)
end;

class procedure TDict.CopyIt(ADict:TDict;var Result:TDict);
begin
  if Result=nil then Exit;
  Result.DICTIDEX:=ADict.DICTIDEX;
  Result.DICTMODE:=ADict.DICTMODE;
  Result.DICTINFO:=ADict.DICTINFO;
  Result.DICTCODE:=ADict.DICTCODE;
  Result.DICTNAME:=ADict.DICTNAME;
  Result.DICTMEMO:=ADict.DICTMEMO;
end;

end.

